<template>
  <div class="box">
    <!-- <el-card> -->
    <div class="header">
      <el-input v-model="input" placeholder="输入道路名称"></el-input>
      <div class="img">
        <img src="@/assets/images/u87.svg" alt="" @click="imgu87" />
        <img src="@/assets/images/u86.svg" alt="" @click="deleteTabelData" />
        <img src="@/assets/images/u88.svg" alt="" />
        <img src="@/assets/images/u89.svg" alt="" />
        <el-button size="mini" @click="btn">返回</el-button>
      </div>
    </div>
    <div class="content">
      <el-table
        :data="tableData"
        style="width: 100%; border-radius: 10px; height: 815px"
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="116" align="center" />
        <el-table-column type="index" label="序号" align="center" width="116">
        </el-table-column>
        <el-table-column prop="roadId" label="道路名称" align="center">
        </el-table-column>
        <el-table-column prop="street" label="是否有绿化工程" align="center">
          <template slot-scope="scope">
            {{ scope.row.landscape == 1 ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="height" label="是否有交通工程" align="center">
          <template slot-scope="scope">
            {{ scope.row.traffic == 1 ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="width" label="是否有安防工程" align="center">
          <template slot-scope="scope">
            {{ scope.row.safety == 1 ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="roadclass" label="是否有照明工程" align="center">
          <template slot-scope="scope">
            {{ scope.row.illumination == 1 ? "是" : "否" }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- </el-card> -->
    <div>
      <el-dialog
        title="新增专业工程信息"
        :visible.sync="dialogVisible"
        :before-close="handleClose"
        :show-close="false"
      >
        <el-form :inline="true">
          <el-form-item label="*道路名称" style="width: 352px">
            <el-select v-model="formData.roadId" placeholder="输入道路名称">
              <el-option
                v-for="item in options"
                :key="item.roadId"
                :label="item.roadName"
                :value="item.roadId"
              >
              </el-option>
            </el-select>
            <div class="line"></div>
          </el-form-item>
          <el-form-item label="*是否有绿化工程">
            <el-select
              v-model="formData.landscape"
              placeholder="输入是否有绿化工程"
            >
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="*是否有交通工程">
            <el-select
              v-model="formData.traffic"
              placeholder="输入是否有交通工程"
            >
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="*是否有安防工程">
            <el-select
              v-model="formData.safety"
              placeholder="输入是否有安防工程"
            >
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="*是否有照明工程">
            <el-select
              v-model="formData.illumination"
              placeholder="输入是否有照明工程"
            >
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleConfirm">提交</el-button>
          <el-button @click="dialogVisible = false">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {
  getProfessionalList,
  getRoadList,
  addProfessionalList,
  deletaProfessionalList,
} from "@/api/collaborativeManagement/index";
export default {
  props: {
    id: {
      type: Number,
    },
  },
  data() {
    return {
      tableData: [
        {
          index: "1",
          roadname: "城市主干道",
          street: "Y",
          height: "Y",
          width: "Y",
          roadclass: "Y",
        },
      ],
      input: "",
      queryForm: {
        pageSize: 10,
        pageNum: 1,
      },
      dialogVisible: false,
      options: [
        {
          value: "选项1",
          label: "道路1",
        },
        {
          value: "选项2",
          label: "道路2",
        },
        {
          value: "选项3",
          label: "道路3",
        },
        {
          value: "选项4",
          label: "道路4",
        },
      ],
      options1: [
        { value: "1", label: "是" },
        { value: "0", label: "否" },
      ],
      value: "",
      formData: {},
      ids: [],
    };
  },

  mounted() {
    this.getTableList();
    this.getRoadTableList();
  },
  methods: {
    getTableList() {
      getProfessionalList(this.queryForm).then((res) => {
        if (res.code == 200) {
          this.tableData = res.rows;
        }
      });
    },
    imgu87() {
      console.log(111);
      this.dialogVisible = true;
    },
    handleConfirm() {
      this.dialogVisible = false;
      this.formData["projectId"] = this.id;
      this.formData["status"] = 1;
      this.formData["greenArea"] = 666;
      this.formData["remark"] = "空";
      addProfessionalList(this.formData).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "新增成功",
          });
          this.getTableList();
        }
      });
    },
    handleClose() {},
    btn() {
      this.$router.push("index");
    },
    //获取道路信息列表
    getRoadTableList() {
      let abc = {
        pageSize: 999,
        pageNum: 1,
        projectId: this.id,
      };
      getRoadList(abc).then((res) => {
        if (res.code == 200) {
          this.options = res.rows;
        }
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.specialtyId);
      console.log(this.ids, selection);
    },
    //删除数据
    deleteTabelData() {
      if (this.ids.length == 0) {
        this.$message({
          message: "请选择要删除的数据",
          type: "warning",
        });
        return;
      }

      this.$confirm("确认删除吗？")
        .then((_) => {
          this.ids.forEach((ele) => {
            deletaProfessionalList(ele);
          });
          setTimeout(() => {
            this.getTableList();
          }, 500);
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.box {
  // .el-card {
  //   height: 965px;
  // }
  .header {
    width: 100%;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-input {
      width: 50%;
    }

    .img {
      width: 200px;
      display: flex;
      justify-content: space-between;

      .el-button {
        background-color: rgb(178, 178, 179);
        color: #ffffff;
      }
    }

    ::v-deep .el-input__inner {
      width: 300px;
      height: 44px;
      border-radius: 10px;
      font-size: 14px;
      border-width: 1px;
      border-style: solid;
      border-color: rgba(215, 215, 215, 1);
    }

    .content {
      height: calc(100% - 60px);
    }
  }

  ::v-deep .el-dialog {
    width: 781px;
    height: 470px;
    border-radius: 20px;
    background-color: #f6f9fb;
    border: none;

    .el-dialog__title {
      font-weight: 650;
      font-size: 20px;
      display: flex;
      justify-content: center;
    }

    .el-form {
      margin-left: 60px;

      .el-form-item__label {
        margin-left: 8px;
        margin-top: -10px;
      }

      .el-form-item {
        width: 310px;

        .el-input__inner {
          width: 300px;
          height: 44px;
          border-radius: 10px;
        }
      }

      .line {
        border-bottom: 1px solid red;
        width: 240px;
        margin-left: 30px;
      }
    }

    .dialog-footer {
      display: flex;
      justify-content: center;
      margin-top: 30px;

      > button:nth-of-type(1) {
        width: 633px;
        height: 54px;
        border-radius: 10px;
        position: absolute;
        bottom: 40px;
      }

      > button:nth-of-type(2) {
        width: 83px;
        height: 36px;
        border-radius: 10px;
        position: absolute;
        right: 15px;
        top: 15px;
      }
    }
  }
}
</style>
